﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace MessMain
{
        public class BlockingQueue<T>
        {
            private Queue<T> q = new Queue<T>();

            public void addString(T element)
            {
                q.Enqueue(element);
                lock (q)
                {
                    Monitor.Pulse(q);
                }
            }

            public T getString()
            {
                lock (q)
                {
                    while (q.Count == 0)
                    {
                        Monitor.Wait(q);
                    }
                    return q.Dequeue();
                }
            }
    }
}
